// $codepro.audit.disable emptyMethod, hidingInheritedFields, methodChainLength, com.instantiations.assist.eclipse.analysis.unusedReturnValue
/**
 * License under GNU's GPL 
 * Doctor.java 
 */


import java.io.IOException;
import java.util.Scanner;
import java.util.logging.FileHandler;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Class represents a doctor
 * 
 * @author Team 9
 * @version 1.0
 * 
 */
public class Doctor extends Nurse {
	/**
	 * Gui window
	 */
	private DoctorGui window;
	
	/**
	 * type of object
	 */
	private int type = 1;
	
	/**
	 * Logger variable
	 */
	public static String Fn;

	/**
	 * Logger variable
	 */
	public static String Ln;

	/**
	 * Logger variable
	 */
	// Logging code
	private static final Logger DOCTORLOGGER = Logger.getLogger("Doctor");

	static {
		FileHandler filehand = null;
		try {
			filehand = new FileHandler("Doctor.log");
		} catch (SecurityException se) {
			DOCTORLOGGER.log(Level.SEVERE,
					"Security Exception creating the logger", se);
			se.printStackTrace();
		} catch (IOException ioe) {
			DOCTORLOGGER.log(Level.SEVERE, "IO Exception creating the logger",
					ioe);
			ioe.printStackTrace();
		}

		filehand.setFilter(new Filter() {
			public boolean isLoggable(LogRecord record) {
				return true;
			}
		});
		DOCTORLOGGER.addHandler(filehand);
		DOCTORLOGGER.setLevel(Level.ALL);
	}// end logging code

	/**
	 * Overrides the toString() method to print the appropriate instance
	 * variables
	 * 
	 * @return String to be printed
	 */
	@Override
	public String toString() {
		return "Doctor [appointment=" + appointment + ", lastName=" + lastName
				+ ", firstName=" + firstName + ", userName=" + userName
				+ ", suspend=" + suspend + "]";
	}

	/**
	 * Empty constructor for the class
	 */
	public Doctor() {
	}

	/**
	 * Constructor for the class
	 * 
	 * @param first
	 *            value for firstName
	 * @param last
	 *            value for lastName
	 * @param user
	 *            value for userName
	 * @param pass
	 *            value for password
	 */
	public Doctor(String first, String last, String user, String pass) {
		lastName = last;
		firstName = first;
		userName = user;
		password = pass;
		suspend = false;
		type = 1;
		DOCTORLOGGER.info("Doctor constructed: " + first + " " + last);

	}

	/**
	 * Method to generate a GUI for the doctor
	 * 
	 */
	@Override
	public void showGUI() {
		window = new DoctorGui(this);
		window.getFrame().setVisible(true);
	}

	/**
	 * Method to add a new doctor's order
	 * 
	 * @param first
	 *            first name of the patient
	 * @param last
	 *            last name of the patient
	 */
	public void addDoctorsOrders(String first, String last) {
		final int index = lookup(first, last);
		final int treatmentSize = Gui.getPatientArray().get(index).getRecords()
				.size();
		Gui.getPatientArray().get(index).getRecords().get(treatmentSize - 1)
				.newDoctorsOrders(); // assumes you are adding to the last
										// appointment
		DOCTORLOGGER.log(Level.FINE, "Dr." + Fn + " " + Ln
				+ " added Doctors Orders for Patient: " + first + " " + last);
	}

	/**
	 * Method to edit an existing treatment records
	 * 
	 * @param first
	 *            first name of the patient to edit
	 * @param last
	 *            last name of the patient to edit
	 */
	public void editTreatmentRecords(String first, String last) {
		final int index = lookup(first, last);
		final int size = Gui.getPatientArray().get(index).getRecords().size();
		int counter = 0;
		final Scanner scan = new Scanner(System.in);
		if (index <= -1) {
			System.out.println("Patient not found");
		} else {
			// loop to go through all appointments so you can choose which
			// treatment records to edit
			if (size != 0) {
				for (counter = 0; counter < size; counter++) {
					System.out.println(Gui.getPatientArray().get(index)
							.getRecords().get(counter).getAppointment()); // prints
																			// out
																			// appointment
																			// date
					System.out
							.println("Edit this Appointment's Treatment Records?");
					String yes = scan.nextLine();
					if ("yes".equalsIgnoreCase(yes)) {
						break;
					}
				}

				System.out.println("Appointment Time and Date");
				final String app = scan.nextLine();
				System.out.println("Attending Nurse");
				final String nurse = scan.nextLine();
				System.out.println("Patient's Chief Complaint");
				final String comp = scan.nextLine();
				System.out.println("Vital Signs"); // want to expand on this???
													// Blood pressure, temp....
				final String vitals = scan.nextLine();
				System.out.println("Diagnosis");
				final String diag = scan.nextLine();

				final TreatmentRecord record = new TreatmentRecord(nurse, comp,
						vitals, diag, last, first, app);
				Gui.getPatientArray().get(index).getRecords()
						.set(index, record);
			} else {
				System.out.println("Patient has no treatment records.");
			}
		}
		DOCTORLOGGER.log(Level.FINE, "Dr." + Fn + " " + Ln
				+ " edited Treatment Records for Patient: " + first + " "
				+ last);

	}

	/**
	 * Method to edit an existing doctor's orders
	 * 
	 * @param first
	 *            first name of the patient to edit
	 * @param last
	 *            last name of the patient to edit
	 */
	public void editDoctorsOrders(String first, String last) {
		final int index = lookup(first, last);
		final int size = Gui.getPatientArray().get(index).getRecords().size();
		int counter = 0;
		final Scanner scan = new Scanner(System.in);
		if (index < 0) {
			System.out.println("Patient not found");
		} else {
			// loop to go through all appointments so you can choose which
			// treatment records to edit
			for (counter = 0; counter < size; counter++) {
				System.out.println(Gui.getPatientArray().get(index)
						.getRecords().get(counter).getAppointment()); // prints
																		// out
																		// appointment
																		// date
				System.out
						.println("Edit this Appointment's Treatment Records?");
				String yes = scan.nextLine();
				if ("yes".equalsIgnoreCase(yes)) {
					break;
				}
			}

			System.out.println("Perscriptions: Enter 1 for Tylenol, "
					+ "2 for Cold Medicine or 3 for Other");
			final int perscript = scan.nextInt();
			System.out.println("Lab Work Performed");
			final String labWP = scan.nextLine();
			System.out.println("Follow Up Instructions");
			final String followUp = scan.nextLine();
			System.out.println("Other Instructions");
			final String otherI = scan.nextLine();

			final DoctorsOrders docOrder = new DoctorsOrders(perscript, labWP,
					followUp, otherI);
			Gui.getPatientArray().get(index).getRecords().get(counter)
					.setOrders(docOrder);
		}
		DOCTORLOGGER.log(Level.FINE, "Dr." + Fn + " " + Ln
				+ " edited Doctors Orders for Patient: " + first + " " + last);
	}

	/**
	 * Method to delete a treatment record
	 * 
	 * @param first
	 *            first name of the patient
	 * @param last
	 *            last name of the patient
	 */
	public void deleteTreatmentRecords(String first, String last) {
		final int index = lookup(first, last);
		final int size = Gui.getPatientArray().get(index).getRecords().size();
		int counter = 0;
		final Scanner scan = new Scanner(System.in);
		if (index < 0) {
			System.out.println("Patient not found");
		} else {
			// loop to go through all appointments so you can choose which
			// treatment records to edit
			for (counter = 0; counter < size; counter++) {
				System.out.println(Gui.getPatientArray().get(index)
						.getRecords().get(counter).getAppointment()); // prints
																		// out
																		// appointment
																		// date
				System.out
						.println("Edit this Appointment's Treatment Records?");
				String yes = scan.nextLine();
				if ("yes".equalsIgnoreCase(yes)) {
					break;
				}
			}

			Gui.getPatientArray().get(index).getRecords().remove(counter);
		}
		DOCTORLOGGER.log(Level.FINE, "Dr." + Fn + " " + Ln
				+ " deleted Treament Records for Patient: " + first + " "
				+ last);
	}

	/**
	 * Method to delete a doctor's order
	 * 
	 * @param first
	 *            first name of the patient
	 * @param last
	 *            last name of the patient
	 */
	public void deleteDoctorsOrders(String first, String last) {
		final int index = lookup(first, last);
		final int size = Gui.getPatientArray().get(index).getRecords().size();
		int counter = 0;
		final Scanner scan = new Scanner(System.in);
		if (index < 0) {
			System.out.println("Patient not found");
		} else {
			// loop to go through all appointments so you can choose which
			// treatment records to edit
			for (counter = 0; counter < size; counter++) {
				System.out.println(Gui.getPatientArray().get(index)
						.getRecords().get(counter).getAppointment()); // prints
																		// out
																		// appointment
																		// date
				System.out
						.println("Edit this Appointment's Treatment Records?");
				String yes = scan.nextLine();
				if ("yes".equalsIgnoreCase(yes)) {
					break;
				}
			}

			Gui.getPatientArray().get(index).getRecords().get(counter)
					.deleteDoctorsOrders();
		}
		DOCTORLOGGER.log(Level.FINE, "Dr." + Fn + " " + Ln
				+ " deleted Doctors Orders for Patient: " + first + " " + last);
	}
}